package com.linkage.jz.bankruptcy.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.bean.CarryOutListInfo;
import com.linkage.jz.bankruptcy.bean.LawListInfo;

import java.util.ArrayList;
import java.util.List;

import cn.bingoogolapple.androidcommon.adapter.BGARecyclerViewAdapter;
import cn.bingoogolapple.androidcommon.adapter.BGAViewHolderHelper;
import cn.bingoogolapple.swipeitemlayout.BGASwipeItemLayout;


public class CarryOutListViewAdapter extends BGARecyclerViewAdapter<CarryOutListInfo> {
    /**
     * 当前处于打开状态的item
     */
    private Context mContext;
    private List<BGASwipeItemLayout> mOpenedSil = new ArrayList<>();

    public CarryOutListViewAdapter(RecyclerView recyclerView ,Context context) {
        super(recyclerView, R.layout.item_carryoutlist);
        mContext =context;
    }

    @Override
    public void setItemChildListener(BGAViewHolderHelper viewHolderHelper, int viewType) {
        BGASwipeItemLayout swipeItemLayout = viewHolderHelper.getView(R.id.sil_item_bgaswipe_root);
        swipeItemLayout.setDelegate(new BGASwipeItemLayout.BGASwipeItemLayoutDelegate() {
            @Override
            public void onBGASwipeItemLayoutOpened(BGASwipeItemLayout swipeItemLayout) {
                closeOpenedSwipeItemLayoutWithAnim();
                mOpenedSil.add(swipeItemLayout);
            }

            @Override
            public void onBGASwipeItemLayoutClosed(BGASwipeItemLayout swipeItemLayout) {
                mOpenedSil.remove(swipeItemLayout);
            }

            @Override
            public void onBGASwipeItemLayoutStartOpen(BGASwipeItemLayout swipeItemLayout) {
                closeOpenedSwipeItemLayoutWithAnim();
            }
        });
        viewHolderHelper.setItemChildClickListener(R.id.tv_item_bgaswipe_delete);
        viewHolderHelper.setItemChildLongClickListener(R.id.tv_item_bgaswipe_delete);
    }

    @Override
    public void fillData(BGAViewHolderHelper viewHolderHelper, int position, CarryOutListInfo model) {
        viewHolderHelper.setText(R.id.tv_item_bgaswipe_title, model.getName())
                .setText(R.id.tv_item_bgaswipe_detail, model.getPhone())
                .setText(R.id.et_item_bgaswipe_title, model.getName());


        ImageView img = (ImageView)viewHolderHelper.getImageView(R.id.iv_item_bgaswipe_avatar);
        Glide.with(mContext).load(model.getLogo())
                .placeholder(R.drawable.nopic)
                .error(R.drawable.nopic).into(img);
//        switch (position+1)
//        {
//            case 1:
//                viewHolderHelper.setBackgroundRes(R.id.iv_item_bgaswipe_avatar,R.drawable.kd_1);
//                break;
//            case 2:
//                viewHolderHelper.setBackgroundRes(R.id.iv_item_bgaswipe_avatar,R.drawable.kd_2);
//                break;
//            case 3:
//                viewHolderHelper.setBackgroundRes(R.id.iv_item_bgaswipe_avatar,R.drawable.kd_3);
//                break;
//            case 4:
//                viewHolderHelper.setBackgroundRes(R.id.iv_item_bgaswipe_avatar,R.drawable.kd_4);
//                break;
//            case 5:
//                viewHolderHelper.setBackgroundRes(R.id.iv_item_bgaswipe_avatar,R.drawable.kd_5);
//                break;
//            case 6:
//                viewHolderHelper.setBackgroundRes(R.id.iv_item_bgaswipe_avatar,R.drawable.kd_6);
//                break;
//            case 7:
//                viewHolderHelper.setBackgroundRes(R.id.iv_item_bgaswipe_avatar,R.drawable.kd_7);
//                break;
//            case 8:
//                viewHolderHelper.setBackgroundRes(R.id.iv_item_bgaswipe_avatar,R.drawable.kd_8);
//                break;
//            case 9:
//                viewHolderHelper.setBackgroundRes(R.id.iv_item_bgaswipe_avatar,R.drawable.kd_9);
//                break;
//            case 10:
//                viewHolderHelper.setBackgroundRes(R.id.iv_item_bgaswipe_avatar,R.drawable.kd_10);
//                break;
//            case 11:
//                viewHolderHelper.setBackgroundRes(R.id.iv_item_bgaswipe_avatar,R.drawable.kd_11);
//                break;
//            case 12:
//                viewHolderHelper.setBackgroundRes(R.id.iv_item_bgaswipe_avatar,R.drawable.kd_12);
//                break;
//            default:
//                break;
//
//
//        }

        BGASwipeItemLayout swipeItemLayout = viewHolderHelper.getView(R.id.sil_item_bgaswipe_root);
//        if (position % 3 == 0) {
            swipeItemLayout.setSwipeAble(false);
//        } else {
//            swipeItemLayout.setSwipeAble(true);
//        }
    }

    public void closeOpenedSwipeItemLayoutWithAnim() {
        for (BGASwipeItemLayout sil : mOpenedSil) {
            sil.closeWithAnim();
        }
        mOpenedSil.clear();
    }
}